// FIT_6204_Gorodilov_GreedySettingsDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FIT_6204_Gorodilov_Greedy.h"
#include "FIT_6204_Gorodilov_GreedySettingsDlg.h"


// FIT_6204_Gorodilov_GreedySettingsDlg dialog

IMPLEMENT_DYNAMIC(CFIT_6204_Gorodilov_GreedySettingsDlg, CDialog)

CFIT_6204_Gorodilov_GreedySettingsDlg::CFIT_6204_Gorodilov_GreedySettingsDlg(CWnd* pParent /*=NULL*/, UINT width, UINT height)
	: CDialog(CFIT_6204_Gorodilov_GreedySettingsDlg::IDD, pParent)
	, m_Width(width)
	, m_Height(height)
{

}

CFIT_6204_Gorodilov_GreedySettingsDlg::~CFIT_6204_Gorodilov_GreedySettingsDlg()
{
}

void CFIT_6204_Gorodilov_GreedySettingsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT1, edit_width);
	DDX_Control(pDX, IDC_EDIT2, edit_height);
}


BEGIN_MESSAGE_MAP(CFIT_6204_Gorodilov_GreedySettingsDlg, CDialog)
	ON_EN_CHANGE(IDC_EDIT1, &CFIT_6204_Gorodilov_GreedySettingsDlg::OnEnChangeEdit1)
	ON_EN_CHANGE(IDC_EDIT2, &CFIT_6204_Gorodilov_GreedySettingsDlg::OnEnChangeEdit2)
END_MESSAGE_MAP()


// FIT_6204_Gorodilov_GreedySettingsDlg message handlers

UINT CFIT_6204_Gorodilov_GreedySettingsDlg::GetWidth(void)
{
	return m_Width;
}

UINT CFIT_6204_Gorodilov_GreedySettingsDlg::GetHeight(void)
{
	return m_Height;
}

BOOL CFIT_6204_Gorodilov_GreedySettingsDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	CString buf;
	buf.Format("%d",m_Width);
	edit_width.SetWindowTextA(buf);
	buf.Format("%d",m_Height);
	edit_height.SetWindowTextA(buf);

	return FALSE;
}

void CFIT_6204_Gorodilov_GreedySettingsDlg::OnEnChangeEdit1()
{
	UINT val = 0;
	CString buf;
	this->edit_width.GetWindowTextA(buf);
	sscanf_s(buf,"%d",&val);
	if ((val > 2000) || (val < 1))
	{
		buf.Format("%d",this->m_Width);
		if (val != 0)
			this->edit_width.SetWindowTextA(buf);
	}
	else
	{
		if (this->m_Width != val)
		{
			this->m_Width = val;
		}
	}
}

void CFIT_6204_Gorodilov_GreedySettingsDlg::OnEnChangeEdit2()
{
	UINT val = 0;
	CString buf;
	this->edit_height.GetWindowTextA(buf);
	sscanf_s(buf,"%d",&val);
	if ((val > 2000) || (val < 1))
	{
		buf.Format("%d",this->m_Height);
		if (val != 0)
			this->edit_height.SetWindowTextA(buf);
	}
	else
	{
		if (this->m_Height != val)
		{
			this->m_Height = val;
		}
	}
}
